﻿using System;
using System.Drawing;
using System.Windows.Forms;
using System.Text;

namespace CustomMessageBox
{
    public class CustomMessageBox
    {
        #region Local Variables
        private static Form messageForm;
        private static TableLayoutPanel messageFormButtonsContainer;
        private static CustomMessageBoxResult result;
        private static bool detailed = false;
        #endregion

        #region Enums
        public enum CustomMessageBoxButtons
        {
            OK,
            OKCancel,
            YesNo,
            YesNoCancel,
            YesYesAllNoNoAll,
            YesYesAllNoNoAllCancel,
            RetryCancel,
            RetryIgnoreCancel,
            AbortRetryIgnore
        }
        public enum CustomMessageBoxResult
        {
            None,
            OK,
            Cancel,
            Abort,
            Retry,
            Ignore,
            Yes,
            YesAll,
            No,
            NoAll
        }
        public enum CustomMessageBoxIcon
        {
            None,
            Error,
            Hand,
            Stop,
            Question,
            Exclamation,
            Warning,
            Information,
            Asterisk,
        }
        public enum CustomMessageBoxDefaultButton
        {
            Button1,
            Button2,
            Button3,
            Button4,
            Button5
        }
        #endregion

        #region Events
        private static void KeyDownEvent(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Escape)
            {
                result = CustomMessageBoxResult.None;
                messageForm.Close();
            }
        }
        private static void cmdOK_Click(object sender, EventArgs e)
        {
            result = CustomMessageBoxResult.OK;
            messageForm.Close();
        }
        private static void cmdAbort_Click(object sender, EventArgs e)
        {
            result = CustomMessageBoxResult.Abort;
            messageForm.Close();
        }
        private static void cmdRetry_Click(object sender, EventArgs e)
        {
            result = CustomMessageBoxResult.Retry;
            messageForm.Close();
        }
        private static void cmdIgnore_Click(object sender, EventArgs e)
        {
            result = CustomMessageBoxResult.Ignore;
            messageForm.Close();
        }
        private static void cmdCancel_Click(object sender, EventArgs e)
        {
            result = CustomMessageBoxResult.Cancel;
            messageForm.Close();
        }
        private static void cmdYes_Click(object sender, EventArgs e)
        {
            result = CustomMessageBoxResult.Yes;
            messageForm.Close();
        }
        private static void cmdYesAll_Click(object sender, EventArgs e)
        {
            result = CustomMessageBoxResult.YesAll;
            messageForm.Close();
        }
        private static void cmdNo_Click(object sender, EventArgs e)
        {
            result = CustomMessageBoxResult.No;
            messageForm.Close();
        }
        private static void cmdNoAll_Click(object sender, EventArgs e)
        {
            result = CustomMessageBoxResult.NoAll;
            messageForm.Close();
        }
        private static void cmdShowDetail_Click(object sender, EventArgs e)
        {
            ShowErrorDetail();
        }
        static void messageForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            CloseForm();
        }
        #endregion

        #region Static Private Methods
        private static void ConfigureButtonsContainer()
        {
            messageFormButtonsContainer = new TableLayoutPanel();
            messageFormButtonsContainer.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
            messageFormButtonsContainer.Name = "tableLayoutPanel1";
            messageFormButtonsContainer.RowCount = 1;
            messageFormButtonsContainer.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
            messageFormButtonsContainer.TabIndex = 0;
            messageFormButtonsContainer.Size = new System.Drawing.Size(30, 38);
            messageFormButtonsContainer.AutoSize = true;

            ConfigureButtonsContainerColumns(1);
            messageForm.Controls.Add(messageFormButtonsContainer);
        }
        private static void ConfigureButtonsContainerColumns(Int32 columns)
        {
            messageFormButtonsContainer.ColumnStyles.Clear();
            messageFormButtonsContainer.ColumnCount = columns;
            for (int i = 0; i < columns; i++)
                messageFormButtonsContainer.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.AutoSize));
        }
        private static void CentralizeButtonsContainer()
        {
            messageFormButtonsContainer.Location = new System.Drawing.Point((messageForm.Width / 2) - (messageFormButtonsContainer.Width / 2),
                messageForm.Size.Height - 70);
        }
        private static void BuildBaseForm()
        {
            messageForm = new Form();
            messageForm.AllowDrop = true;
            messageForm.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            messageForm.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            messageForm.AutoSize = true;
            messageForm.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowOnly;
            messageForm.CausesValidation = false;
            messageForm.ClientSize = new System.Drawing.Size(1, 1);
            messageForm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
            messageForm.MaximizeBox = false;
            messageForm.MinimizeBox = false;
            messageForm.Name = "frmMessageBox";
            messageForm.ShowIcon = true;
            messageForm.ShowInTaskbar = true;
            messageForm.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            messageForm.TopMost = true;
            messageForm.MinimumSize = new System.Drawing.Size(200, 120);
            messageForm.KeyDown += new KeyEventHandler(KeyDownEvent);
            messageForm.Icon = global::CustomMessageBox.Properties.Resources.POSTS;
            messageForm.FormClosing += new FormClosingEventHandler(messageForm_FormClosing);
            ConfigureButtonsContainer();
        }
        private static void AddMessageLabel(String message, bool hasIcon)
        {
            if (!String.IsNullOrEmpty(message))
            {
                Label lbMessage = new Label();
                lbMessage.Location = new System.Drawing.Point(hasIcon ? 66 : 20, 20);
                lbMessage.AutoSize = true;
                lbMessage.Text = message;
                lbMessage.BackColor = Color.Transparent;
                messageForm.Controls.Add(lbMessage);
            }
        }
        private static void AddIcon(CustomMessageBoxIcon icon)
        {
            if (icon != CustomMessageBoxIcon.None)
            {
                PictureBox pbIcon = new PictureBox();
                pbIcon.Name = "pbMessageIcon";
                pbIcon.Size = new System.Drawing.Size(40, 40);
                pbIcon.Location = new System.Drawing.Point(10, 10);
                pbIcon.SizeMode = PictureBoxSizeMode.StretchImage;
                switch (icon)
                {
                    case CustomMessageBoxIcon.Error:
                        pbIcon.Image = global::CustomMessageBox.Properties.Resources.error;
                        break;
                    case CustomMessageBoxIcon.Hand:
                        pbIcon.Image = global::CustomMessageBox.Properties.Resources.error;
                        break;
                    case CustomMessageBoxIcon.Stop:
                        pbIcon.Image = global::CustomMessageBox.Properties.Resources.error;
                        break;
                    case CustomMessageBoxIcon.Question:
                        pbIcon.Image = global::CustomMessageBox.Properties.Resources.question;
                        break;
                    case CustomMessageBoxIcon.Exclamation:
                        pbIcon.Image = global::CustomMessageBox.Properties.Resources.warning;
                        break;
                    case CustomMessageBoxIcon.Warning:
                        pbIcon.Image = global::CustomMessageBox.Properties.Resources.warning;
                        break;
                    case CustomMessageBoxIcon.Information:
                        pbIcon.Image = global::CustomMessageBox.Properties.Resources.info;
                        break;
                    case CustomMessageBoxIcon.Asterisk:
                        pbIcon.Image = global::CustomMessageBox.Properties.Resources.info;
                        break;
                }
                messageForm.Controls.Add(pbIcon);
            }
        }
        private static void AddButtons(CustomMessageBoxButtons buttons)
        {
            switch (buttons)
            {
                case CustomMessageBoxButtons.OK:
                    ConfigureButtonsContainerColumns(1);
                    AddOKButton();
                    break;
                case CustomMessageBoxButtons.OKCancel:
                    ConfigureButtonsContainerColumns(2);
                    AddOKCancelButton();
                    break;
                case CustomMessageBoxButtons.YesNo:
                    ConfigureButtonsContainerColumns(2);
                    AddYesNoButton();
                    break;
                case CustomMessageBoxButtons.YesNoCancel:
                    ConfigureButtonsContainerColumns(3);
                    AddYesNoCancelButton();
                    break;
                case CustomMessageBoxButtons.YesYesAllNoNoAll:
                    ConfigureButtonsContainerColumns(4);
                    AddYesYesAllNoNoAll();
                    break;
                case CustomMessageBoxButtons.YesYesAllNoNoAllCancel:
                    ConfigureButtonsContainerColumns(5);
                    AddYesYesAllNoNoAllCancelButton();
                    break;
                case CustomMessageBoxButtons.RetryCancel:
                    ConfigureButtonsContainerColumns(2);
                    AddRetryCancelButton();
                    break;
                case CustomMessageBoxButtons.RetryIgnoreCancel:
                    ConfigureButtonsContainerColumns(3);
                    AddRetryIgnoreCancelButton();
                    break;
                case CustomMessageBoxButtons.AbortRetryIgnore:
                    ConfigureButtonsContainerColumns(3);
                    AddAbortRetryIgnoreButton();
                    break;
            }
            CentralizeButtonsContainer();
            CheckFormWidthAgainstButtons();
        }
        private static void CheckFormWidthAgainstButtons()
        {
            Int32 desiredWidth = messageFormButtonsContainer.Width + 60;
            if (messageForm.Width < desiredWidth)
                messageForm.Size = new Size(desiredWidth, messageForm.Size.Height);
        }
        private static void AddOKButton()
        {
            AddButton(0, "OK", new EventHandler(cmdOK_Click));
        }
        private static void AddOKCancelButton()
        {
            AddButton(0, "OK", new EventHandler(cmdOK_Click));
            AddButton(1, "Cancel", new EventHandler(cmdCancel_Click));
        }
        private static void AddYesNoButton()
        {
            AddButton(0, "Yes", new EventHandler(cmdYes_Click));
            AddButton(1, "No", new EventHandler(cmdNo_Click));
        }
        private static void AddYesNoCancelButton()
        {
            AddButton(0, "Yes", new EventHandler(cmdYes_Click));
            AddButton(1, "No", new EventHandler(cmdNo_Click));
            AddButton(2, "Cancel", new EventHandler(cmdCancel_Click));
        }
        private static void AddYesYesAllNoNoAll()
        {
            AddButton(0, "Yes", new EventHandler(cmdYes_Click));
            AddButton(1, "Yes All", new EventHandler(cmdYesAll_Click));
            AddButton(2, "No", new EventHandler(cmdNo_Click));
            AddButton(3, "No All", new EventHandler(cmdNoAll_Click));
        }
        private static void AddYesYesAllNoNoAllCancelButton()
        {
            AddButton(0, "Yes", new EventHandler(cmdYes_Click));
            AddButton(1, "Yes All", new EventHandler(cmdYesAll_Click));
            AddButton(2, "No", new EventHandler(cmdNo_Click));
            AddButton(3, "No All", new EventHandler(cmdNoAll_Click));
            AddButton(4, "Cancel", new EventHandler(cmdCancel_Click));
        }
        private static void AddRetryCancelButton()
        {
            AddButton(0, "Retry", new EventHandler(cmdRetry_Click));
            AddButton(1, "Cancel", new EventHandler(cmdCancel_Click));
        }
        private static void AddRetryIgnoreCancelButton()
        {
            AddButton(0, "Retry", new EventHandler(cmdRetry_Click));
            AddButton(1, "Ignore", new EventHandler(cmdIgnore_Click));
            AddButton(2, "Cancel", new EventHandler(cmdCancel_Click));
        }
        private static void AddAbortRetryIgnoreButton()
        {
            AddButton(0, "Abort", new EventHandler(cmdAbort_Click));
            AddButton(1, "Retry", new EventHandler(cmdRetry_Click));
            AddButton(2, "Ignore", new EventHandler(cmdIgnore_Click));
        }
        private static void AddButton(Int32 column, String name, EventHandler eventMethod)
        {
            Button commandButton = new Button();
            commandButton.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
            commandButton.Name = "Button" + Convert.ToString(column + 1);
            commandButton.Size = new System.Drawing.Size(60, 23);
            commandButton.TabIndex = column;
            commandButton.Text = name;
            commandButton.UseVisualStyleBackColor = true;
            commandButton.Click += eventMethod;
            commandButton.KeyDown += new KeyEventHandler(KeyDownEvent);
            commandButton.ForeColor = Color.Black;
            messageFormButtonsContainer.Controls.Add(commandButton, column, 0);
        }
        private static void ShowWindow(IWin32Window owner)
        {
            if (owner != null)
                messageForm.ShowDialog(owner);
            else
                messageForm.ShowDialog();
        }
        private static void SetDefaultButton(CustomMessageBoxDefaultButton defaultButton)
        {
            Control[] cmdFound = messageForm.Controls.Find(defaultButton.ToString(), true);
            if (cmdFound != null && cmdFound.Length > 0)
            {
                ((Button)cmdFound[0]).Focus();
                messageForm.AcceptButton = (IButtonControl)cmdFound[0];
            }
        }
        private static void SetWindowStyle(CustomMessageBoxStyle style)
        {
            if (style != null && messageForm != null)
            {
                if (style.BackColor != Color.Transparent)
                    messageForm.BackColor = style.BackColor;
                messageForm.ForeColor = style.ForeColor;
                SetContainersTransparent(messageForm.Controls);
            }
        }
        private static void SetBackGroundImage(Image backGroundImage, ImageLayout imageLayout)
        {
            if (backGroundImage != null)
            {
                messageForm.BackgroundImage = backGroundImage;
                messageForm.BackgroundImageLayout = imageLayout;
                SetContainersTransparent(messageForm.Controls);
            }
        }
        private static void SetContainersTransparent(Control.ControlCollection controlCollection)
        {
            if (controlCollection != null && controlCollection.Count > 0)
            {
                foreach (Control item in controlCollection)
                {
                    if (item is GroupBox ||
                        item is Panel ||
                        item is SplitContainer ||
                        item is Label ||
                        item is PictureBox)
                        item.BackColor = Color.Transparent;

                    if (item.Controls != null && item.Controls.Count > 0)
                        SetContainersTransparent(item.Controls);
                }
            }
        }
        private static void BuildErrorForm(String operation, Exception ex)
        {
            PictureBox pictureBox1 = new System.Windows.Forms.PictureBox();
            Label label1 = new System.Windows.Forms.Label();
            Label lblOperationName = new System.Windows.Forms.Label();
            GroupBox groupBox1 = new System.Windows.Forms.GroupBox();
            TextBox txtErrorMessage = new System.Windows.Forms.TextBox();
            Button cmdShowDetail = new System.Windows.Forms.Button();
            GroupBox groupBox2 = new System.Windows.Forms.GroupBox();
            TextBox txtErrorDetail = new System.Windows.Forms.TextBox();
            ((System.ComponentModel.ISupportInitialize)(pictureBox1)).BeginInit();
            groupBox1.SuspendLayout();
            groupBox2.SuspendLayout();

            // 
            // pictureBox1
            // 
            pictureBox1.Image = global::CustomMessageBox.Properties.Resources.error;
            pictureBox1.Location = new System.Drawing.Point(13, 13);
            pictureBox1.Name = "pictureBox1";
            pictureBox1.Size = new System.Drawing.Size(30, 30);
            pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
            pictureBox1.TabIndex = 0;
            pictureBox1.TabStop = false;
            // 
            // label1
            // 
            label1.AutoSize = true;
            label1.Location = new System.Drawing.Point(49, 13);
            label1.Name = "label1";
            label1.Size = new System.Drawing.Size(182, 13);
            label1.TabIndex = 1;
            label1.Text = "Ocorreu um erro durante a operação:";
            // 
            // lblOperationName
            // 
            lblOperationName.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            lblOperationName.Location = new System.Drawing.Point(49, 30);
            lblOperationName.Name = "lblOperationName";
            lblOperationName.Size = new System.Drawing.Size(496, 13);
            lblOperationName.TabIndex = 2;
            lblOperationName.Text = "Operation Name";
            // 
            // groupBox1
            // 
            groupBox1.Controls.Add(txtErrorMessage);
            groupBox1.Location = new System.Drawing.Point(13, 49);
            groupBox1.Name = "groupBox1";
            groupBox1.Size = new System.Drawing.Size(586, 141);
            groupBox1.TabIndex = 3;
            groupBox1.TabStop = false;
            groupBox1.Text = "Mensagem de Erro";
            // 
            // txtErrorMessage
            // 
            txtErrorMessage.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                   | System.Windows.Forms.AnchorStyles.Left)
                   | System.Windows.Forms.AnchorStyles.Right)));
            txtErrorMessage.Location = new System.Drawing.Point(7, 20);
            txtErrorMessage.Multiline = true;
            txtErrorMessage.Name = "txtErrorMessage";
            txtErrorMessage.ReadOnly = true;
            txtErrorMessage.ScrollBars = System.Windows.Forms.ScrollBars.Both;
            txtErrorMessage.Size = new System.Drawing.Size(573, 113);
            txtErrorMessage.TabIndex = 0;
            txtErrorMessage.TabStop = false;
            txtErrorMessage.KeyDown += new KeyEventHandler(KeyDownEvent);
            // 
            // cmdShowDetail
            // 
            cmdShowDetail.Location = new System.Drawing.Point(13, 196);
            cmdShowDetail.Name = "cmdShowDetail";
            cmdShowDetail.Size = new System.Drawing.Size(75, 23);
            cmdShowDetail.TabIndex = 4;
            cmdShowDetail.Text = "&Detalhes >>";
            cmdShowDetail.UseVisualStyleBackColor = true;
            cmdShowDetail.Click += new System.EventHandler(cmdShowDetail_Click);
            cmdShowDetail.KeyDown += new KeyEventHandler(KeyDownEvent);
            // 
            // groupBox2
            // 
            groupBox2.Controls.Add(txtErrorDetail);
            groupBox2.Location = new System.Drawing.Point(13, 239);
            groupBox2.Name = "groupBox2";
            groupBox2.Size = new System.Drawing.Size(586, 176);
            groupBox2.TabIndex = 5;
            groupBox2.TabStop = false;
            groupBox2.Text = "Detalhes";
            // 
            // txtErrorDetail
            // 
            txtErrorDetail.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                   | System.Windows.Forms.AnchorStyles.Left)
                   | System.Windows.Forms.AnchorStyles.Right)));
            txtErrorDetail.BackColor = System.Drawing.SystemColors.Control;
            txtErrorDetail.Location = new System.Drawing.Point(7, 20);
            txtErrorDetail.Multiline = true;
            txtErrorDetail.Name = "txtErrorDetail";
            txtErrorDetail.ReadOnly = true;
            txtErrorDetail.ScrollBars = System.Windows.Forms.ScrollBars.Both;
            txtErrorDetail.Size = new System.Drawing.Size(573, 148);
            txtErrorDetail.TabIndex = 0;
            txtErrorDetail.KeyDown += new KeyEventHandler(KeyDownEvent);

            messageForm = new Form();
            messageForm.AcceptButton = cmdShowDetail;
            messageForm.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            messageForm.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            messageForm.ClientSize = new System.Drawing.Size(611, 227);
            messageForm.Controls.Add(groupBox2);
            messageForm.Controls.Add(cmdShowDetail);
            messageForm.Controls.Add(groupBox1);
            messageForm.Controls.Add(lblOperationName);
            messageForm.Controls.Add(label1);
            messageForm.Controls.Add(pictureBox1);
            messageForm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
            messageForm.MaximizeBox = false;
            messageForm.MinimizeBox = false;
            messageForm.Name = "FrmErrorMessage";
            messageForm.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            messageForm.TopMost = true;
            messageForm.KeyDown += new KeyEventHandler(KeyDownEvent);
            messageForm.Icon = global::CustomMessageBox.Properties.Resources.POSTS;
            messageForm.Text = "Erro";
            messageForm.FormClosing += new FormClosingEventHandler(messageForm_FormClosing);
            ((System.ComponentModel.ISupportInitialize)(pictureBox1)).EndInit();
            groupBox1.ResumeLayout(false);
            groupBox1.PerformLayout();
            groupBox2.ResumeLayout(false);
            groupBox2.PerformLayout();

            lblOperationName.Text = operation;
            txtErrorMessage.Text = ex.Message;
            txtErrorDetail.Text = GetFullException(ex);
        }
        private static void ShowErrorDetail()
        {
            if (!detailed)
            {
                messageForm.Size = new Size(617, 455);
                detailed = true;
            }
            else
            {
                detailed = false;
                messageForm.Size = new Size(617, 259);
            }
        }
        private static String GetFullException(Exception ex)
        {
            StringBuilder message = new StringBuilder(ex != null ? ex.ToString() : String.Empty);
            if (ex != null && ex.InnerException != null)
                message.Append(GetFullException(ex.InnerException));
            return message.ToString();
        }
        private static void CloseForm()
        {
            detailed = false;
        }
        #endregion

        #region Static Public Methods
        public static CustomMessageBoxResult Show(String message)
        {
            return Show(message, null as IWin32Window);
        }
        public static CustomMessageBoxResult Show(String message, CustomMessageBoxStyle style)
        {
            return Show(message, null as IWin32Window, style);
        }
        public static CustomMessageBoxResult Show(String message, String titulo)
        {
            return Show(message, null as IWin32Window, titulo);
        }
        public static CustomMessageBoxResult Show(String message, String titulo, CustomMessageBoxStyle style)
        {
            return Show(message, null, titulo, style);
        }
        public static CustomMessageBoxResult Show(String message, String titulo, CustomMessageBoxButtons botoes)
        {
            return Show(message, null, titulo, botoes);
        }
        public static CustomMessageBoxResult Show(String message, String titulo, CustomMessageBoxButtons botoes, CustomMessageBoxStyle style)
        {
            return Show(message, null as IWin32Window, titulo, botoes, style);
        }
        public static CustomMessageBoxResult Show(String message, String titulo, CustomMessageBoxButtons botoes, CustomMessageBoxIcon icone)
        {
            return Show(message, null as IWin32Window, titulo, botoes, icone);
        }
        public static CustomMessageBoxResult Show(String message, String titulo, CustomMessageBoxButtons botoes, CustomMessageBoxIcon icone, CustomMessageBoxStyle style)
        {
            return Show(message, null as IWin32Window, titulo, botoes, icone, style);
        }
        public static CustomMessageBoxResult Show(String message, String titulo, CustomMessageBoxButtons botoes, CustomMessageBoxIcon icone, CustomMessageBoxDefaultButton defaultButton)
        {
            return Show(message, null, titulo, botoes, icone, defaultButton);
        }
        public static CustomMessageBoxResult Show(String message, String titulo, CustomMessageBoxButtons botoes, CustomMessageBoxIcon icone, CustomMessageBoxDefaultButton defaultButton, CustomMessageBoxStyle style, Image backGroundImage, ImageLayout imageLayout)
        {
            return Show(message, null as IWin32Window, titulo, botoes, icone, defaultButton, style, backGroundImage, imageLayout);
        }
        public static CustomMessageBoxResult Show(String message, IWin32Window owner)
        {
            return Show(message, owner, null as CustomMessageBoxStyle);
        }
        public static CustomMessageBoxResult Show(String message, IWin32Window owner, CustomMessageBoxStyle style)
        {
            BuildBaseForm();
            AddMessageLabel(message, false);
            SetWindowStyle(style);
            AddButtons(CustomMessageBoxButtons.OK);
            ShowWindow(owner);
            return result;
        }
        public static CustomMessageBoxResult Show(String message, IWin32Window owner, String titulo)
        {
            return Show(message, owner, titulo, null as CustomMessageBoxStyle);
        }
        public static CustomMessageBoxResult Show(String message, IWin32Window owner, String titulo, CustomMessageBoxStyle style)
        {
            BuildBaseForm();
            messageForm.Text = titulo;
            AddMessageLabel(message, false);
            SetWindowStyle(style);
            AddButtons(CustomMessageBoxButtons.OK);
            ShowWindow(owner);
            return result;
        }
        public static CustomMessageBoxResult Show(String message, IWin32Window owner, String titulo, CustomMessageBoxButtons botoes)
        {
            return Show(message, owner, titulo, botoes, null as CustomMessageBoxStyle);
        }
        public static CustomMessageBoxResult Show(String message, IWin32Window owner, String titulo, CustomMessageBoxButtons botoes, CustomMessageBoxStyle style)
        {
            BuildBaseForm();
            messageForm.Text = titulo;
            AddMessageLabel(message, true);
            SetWindowStyle(style);
            AddButtons(botoes);
            ShowWindow(owner);
            return result;
        }
        public static CustomMessageBoxResult Show(String message, IWin32Window owner, String titulo, CustomMessageBoxButtons botoes, CustomMessageBoxIcon icone)
        {
            return Show(message, owner, titulo, botoes, icone, null as CustomMessageBoxStyle);
        }
        public static CustomMessageBoxResult Show(String message, IWin32Window owner, String titulo, CustomMessageBoxButtons botoes, CustomMessageBoxIcon icone, CustomMessageBoxStyle style)
        {
            BuildBaseForm();
            messageForm.Text = titulo;
            AddMessageLabel(message, true);
            AddIcon(icone);
            SetWindowStyle(style);
            AddButtons(botoes);
            ShowWindow(owner);
            return result;
        }
        public static CustomMessageBoxResult Show(String message, IWin32Window owner, String titulo, CustomMessageBoxButtons botoes, CustomMessageBoxIcon icone, CustomMessageBoxDefaultButton defaultButton)
        {
            return Show(message, owner, titulo, botoes, icone, defaultButton, null as CustomMessageBoxStyle, null as Image, ImageLayout.Stretch);
        }
        public static CustomMessageBoxResult Show(String message, IWin32Window owner, String titulo, CustomMessageBoxButtons botoes, CustomMessageBoxIcon icone, CustomMessageBoxDefaultButton defaultButton, CustomMessageBoxStyle style, Image backGroundImage, ImageLayout imageLayout)
        {
            BuildBaseForm();
            messageForm.Text = titulo;
            AddMessageLabel(message, true);
            AddIcon(icone);
            SetDefaultButton(defaultButton);
            SetWindowStyle(style);
            AddButtons(botoes);
            SetBackGroundImage(backGroundImage, imageLayout);
            ShowWindow(owner);
            return result;
        }
        public static CustomMessageBoxResult ShowError(String description, Exception ex)
        {
            return ShowError(description, ex, null);
        }
        public static CustomMessageBoxResult ShowError(String description, Exception ex, CustomMessageBoxStyle style)
        {
            return ShowError(description, ex, style, null, ImageLayout.Stretch);
        }
        public static CustomMessageBoxResult ShowError(String description, Exception ex, CustomMessageBoxStyle style, Image image, ImageLayout layout)
        {
            BuildErrorForm(description, ex);
            SetWindowStyle(style);
            SetBackGroundImage(image, layout);
            messageForm.Text = "Error";
            ShowWindow(null);
            return CustomMessageBoxResult.OK;
        }
        public static CustomMessageBoxResult ShowError(String description, Exception ex, Image image, ImageLayout layout)
        {
            return ShowError(description, ex, null, image, layout);
        }
        public static CustomMessageBoxResult ShowError(String description, IWin32Window owner, Exception ex)
        {
            return ShowError(description, owner, ex, null, null, ImageLayout.Stretch);
        }
        public static CustomMessageBoxResult ShowError(String description, IWin32Window owner, Exception ex, CustomMessageBoxStyle style)
        {
            return ShowError(description, owner, ex, style, null, ImageLayout.Stretch);
        }
        public static CustomMessageBoxResult ShowError(String description, IWin32Window owner, Exception ex, CustomMessageBoxStyle style, Image image, ImageLayout layout)
        {
            BuildErrorForm(description, ex);
            SetWindowStyle(style);
            SetBackGroundImage(image, layout);
            messageForm.Text = "Error";
            ShowWindow(owner);
            return CustomMessageBoxResult.OK;
        }
        public static CustomMessageBoxResult ShowError(String description, IWin32Window owner, Exception ex, Image image, ImageLayout layout)
        {
            return ShowError(description, owner, ex, null, image, layout);
        }
        #endregion
    }

    #region Custom Style Class
    public class CustomMessageBoxStyle
    {
        public CustomMessageBoxStyle() { }
        public CustomMessageBoxStyle(Color backColor, Color foreColor)
        {
            this.BackColor = backColor;
            this.ForeColor = foreColor;
        }

        public Color BackColor { get; set; }
        public Color ForeColor { get; set; }
    }
    #endregion
}
